function dow1(url, options = {}) {
	return downloadFile({
		...options,
		url
	})
}

function downloadFile(options = {}) {
	options = Object.assign({}, options);
	const header = {}
	Object.assign(header, options.header)
	return new Promise((reslove, reject) => {
		const downloadTask = uni.downloadFile({
			timeout: 60000,
			...options,
			header,
			success: res => {
				if (!checkStatusCode(res.statusCode)) return reject(res);
				reslove(res);
			},
			fail: err => {
				reject(err);
			}
		});
		downloadTask.onProgressUpdate(res => {
			if (typeof options.onProgressUpdate === 'function') {
				downloadTask.onProgressUpdate(res)
			}
		});
	});
}

function checkStatusCode(statusCode) {
	return statusCode >= 200 && statusCode < 300 && statusCode != 201 && statusCode != 202 || statusCode === 304;
}

module.exports = {
	dow1
}
